package com.wan.nettyproject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by itsxzx008 on 2016/5/4.
 */
public class ChatAdapter extends BaseAdapter{
    private ArrayList<MessageEnty> datas;
    private LayoutInflater inflater;
    public ChatAdapter(Context context,ArrayList<MessageEnty> datats){
        inflater=LayoutInflater.from(context);
        this.datas=datats;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.adapter_chat,null);
            holder=new ViewHolder();
            holder.tv_content= (TextView) convertView.findViewById(R.id.tv_content);
            holder.tv_who= (TextView) convertView.findViewById(R.id.tv_who);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_who.setText(datas.get(position).getFrom());
holder.tv_content.setText(datas.get(position).getContent());
        return convertView;
    }
    class ViewHolder{
        TextView tv_who,tv_content;
    }
}
